home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_400
/
433_01
/
svgadem1.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-05-08
|
26KB
|
1,168 lines
/****************************************************************************
'SVGACC' A Super Vga Graphics Library for use with Microsoft and
Borland C/C++
Copyright 1993-1994 by Stephen L. Balkum and Daniel A. Sill
GIF and 'Graphics Intechange Format' are trademarks (tm) of
Compuserve, Incorporated, an H&R Block Company.
**************** UNREGISTERD SHAREWARE VERSION ***********************
* FOR EVUALATION ONLY. NOT FOR RESALE IN ANY FORM. SOFTWARE WRITTEN *
* USING THIS UNREGISTERED SHAREWARE GRAPHICS LIBRARY MAY NOT BY SOLD *
* OR USED FOR ANY PURPOSE OTHER THAN THE EVUALTION OF THIS LIBRARY. *
**********************************************************************
**************** NO WARRANTIES AND NO LIABILITY **********************
* Stephen L. Balkum and Daniel A. Sill provide no warranties, either *
* expressed or implied, of merchantability, or fitness, for a *
* particular use or purpose of this SOFTWARE and documentation. *
* In no event shall Stephen L. Balkum or Daniel A. Sill be held *
* liable for any damages resulting from the use or misuse of the *
* SOFTWARE and documentation. *
**********************************************************************
************** U.S. GOVERNMENT RESTRICTED RIGHTS *********************
* Use, duplication, or disclosure of the SOFTWARE and documentation *
* by the U.S. Government is subject to the restictions as set forth *
* in subparagraph (c)(1)(ii) of the Rights in Technical Data and *
* Computer Software cluse at DFARS 252.227-7013. *
* Contractor/manufacturer is Stephen L. Balkum and Daniel A. Sill, *
* P.O. Box 7704, Austin, Texas 78713-7704 *
**********************************************************************
**********************************************************************
* By using this SOFTWARE or documentation, you agree to the above *
* terms and conditions. *
**********************************************************************
***************************************************************************/
#define MODULE
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
#include <math.h>
#include "svgacc.h"
#include "svgademo.h"
#define randnum(size) (rand() % (int)(size))
/***********
* DOBLOCK *
***********/
char doblock(void)
{
int i, colr;
int xinc, yinc, x1, y1, x2, y2;
int cntx, cnty;
char ret;
char title[TITLEN];
char buf[TITLEN];
RasterBlock far *gfxblk;
RasterBlock far *gfxblk2;
RasterBlock far *spritebkgnd;
/*
* Set up the Title
*/
sprintf(title,"DEMO 5: Block function and Sprites");
palset(pal,0,255);
/*
* Show Block Get (draw some circles and "get a chunk of them")
*/
fillscreen(0);
setview(0,0,maxx,maxy);
drwstring(1,7,0,title,10,0);
sprintf(buf,"blkget(x1,y1,x2,y2,GfxBlock);");
drwstring(1,7,0,buf,10,16);
colr = 16;
for(i=0;i<=maxx/2;i++) {
drwcircle(1,colr,maxx/4+i,maxy/2,maxy/5);
colr+=2;
if(colr>255)
colr = 16;
}
xinc = maxx/20;
yinc = maxy/20;
x1 = maxx/2-xinc;
y1 = maxy/2-yinc;
x2 = maxx/2+xinc;
y2 = maxy/2+yinc;
i = (x2-x1+1)*(y2-y1+1)+4;
gfxblk = _fmalloc(i);
if (!gfxblk) {
restext();
printf("ERROR: Allocating memory for gfxblk: %d bytes\n",i);
exit(1);
}
drwbox(1,0,x1,y1,x2,y2);
blkget(x1,y1,x2,y2,gfxblk);
ret = getkey();
if ((ret == 's') || (ret == 'q')) {
fillscreen(0);
_ffree(gfxblk);
return(ret);
}
/*
* Show Block Rotate and Sprite Stuff
*/
drwstring(1,7,0,title,10,0);
sprintf(buf,"blkrotate(angle,backfill,GfxBlockSrc,GfxBlockDst);");
drwstring(1,7,0,buf,10,16);
sprintf(buf,"spritegap(transcolor,x,y,SpriteArray,BkGndArray);");
drwstring(1,7,0,buf,10,32);
sprintf(buf,"spriteput(transcolor,x,y,SpriteArray);");
drwstring(1,7,0,buf,10,48);
cntx = (x2-x1) / 2 + x1;
cnty = (y2-y1) / 2 + y1;
fillarea(x1+2,y1+2,0,0);
i = blkrotatesize(45,gfxblk);
spritebkgnd = _fmalloc(i);
if (!spritebkgnd) {
restext();
printf("ERROR: Allocating memory for spritebkgnd: %d bytes\n",i);
exit(1);
}
gfxblk2 = _fmalloc(i);
if (!gfxblk2) {
restext();
printf("ERROR: Allocating memory for gfxblk2: %d bytes\n",i);
exit(1);
}
blkget(x1,y1,x2,y2,spritebkgnd);
setview(0,64,maxx,maxy);
for(i=0;i<=360;i+=4) {
blkrotate(i,1,gfxblk,gfxblk2);
spriteput(SET,1,cntx-(spritebkgnd->width)/2,cnty-(spritebkgnd->height)/2,spritebkgnd);
spritegap(1,cntx-(gfxblk2->width)/2,cnty-(gfxblk2->height)/2,gfxblk2,spritebkgnd);
sdelay(4);
}
spriteput(SET,1,cntx-(spritebkgnd->width)/2,cnty-(spritebkgnd->height)/2,spritebkgnd);
blkput(SET,x1,y1,gfxblk);
setview(0,0,maxx,maxy);
ret = getkey();
if ((ret == 's') || (ret == 'q')) {
fillscreen(0);
palset(pal,16,255);
_ffree(gfxblk);
_ffree(gfxblk2);
_ffree(spritebkgnd);
return(ret);
}
/*
* Show Block Resize and Sprite Stuff
*/
drwstring(1,7,0,title,10,0);
sprintf(buf,"blkresize(Width,Height,GfxBlockSrc,GfxBlockDst);");
drwstring(1,7,0,buf,10,16);
sprintf(buf,"spritegap(transcolor,x,y,SpriteArray,BkGndArray);");
drwstring(1,7,0,buf,10,32);
sprintf(buf,"spriteput(transcolor,x,y,SpriteArray);");
drwstring(1,7,0,buf,10,48);
fillarea(x1+2,y1+2,0,0);
blkget(x1,y1,x2,y2,spritebkgnd);
setview(0,64,maxx,maxy);
i = (x2-x1+1+xinc)*(y2-y1+1+xinc)+4;
spritebkgnd = _frealloc(spritebkgnd,i);
if (!spritebkgnd) {
restext();
printf("ERROR: reallocating memory for spritebkgnd: %d bytes\n",i);
exit(1);
}
gfxblk2 = _frealloc(gfxblk2,i);
if (!gfxblk2) {
restext();
printf("ERROR: reallocating memory for gfxblk2: %d bytes\n",i);
exit(1);
}
for(i=0;i<=xinc;i++) {
blkresize((gfxblk->width)-i,(gfxblk->height)-i,gfxblk,gfxblk2);
spriteput(SET,1,cntx-(spritebkgnd->width)/2,cnty-(spritebkgnd->height)/2,spritebkgnd);
spritegap(1,cntx-(gfxblk2->width)/2,cnty-(gfxblk2->height)/2,gfxblk2,spritebkgnd);
sdelay(3);
}
spriteput(SET,1,cntx-(spritebkgnd->width)/2,cnty-(spritebkgnd->height)/2,spritebkgnd);
for(i=xinc;i>=0;i--) {
blkresize((gfxblk->width)-i,(gfxblk->height)-i,gfxblk,gfxblk2);
spriteput(SET,1,cntx-(spritebkgnd->width)/2,cnty-(spritebkgnd->height)/2,spritebkgnd);
spritegap(1,cntx-(gfxblk2->width)/2,cnty-(gfxblk2->height)/2,gfxblk2,spritebkgnd);
sdelay(3);
}
spriteput(SET,1,cntx-(spritebkgnd->width)/2,cnty-(spritebkgnd->height)/2,spritebkgnd);
blkput(SET,x1,y1,gfxblk);
ret = getkey();
if ((ret == 's') || (ret == 'q')) {
fillscreen(0);
palset(pal,16,255);
setview(0,0,maxx,maxy);
_ffree(gfxblk);
_ffree(gfxblk2);
_ffree(spritebkgnd);
return(ret);
}
/*
* Show Block Put (put the "chunks" randomly around the screen)
*/
setview(0,16,maxx,32);
fillview(0);
sprintf(buf,"blkput(mode,x,y,GfxBlock);");
drwstring(1,7,0,buf,10,16);
xinc = maxx/10;
yinc = maxy/10;
setview(0,32,maxx,maxy);
for(i=0;i<=maxx/2;i++) {
x1 = randnum(maxx + xinc) - xinc;
y1 = randnum(maxy + yinc) - yinc;
blkput(1,x1,y1,gfxblk);
}
_ffree(gfxblk);
_ffree(gfxblk2);
_ffree(spritebkgnd);
setview(0,0,maxx,maxy);
ret = getkey();
if ((ret == 's') || (ret == 'q')) {
fillscreen(0);
return(ret);
}
return(ret);
}
/**********
* DOCLIP *
**********/
char doclip(void)
{
struct dcoord {
int x1;
int x2;
int y1;
int y2;
};
int i, j, k;
int xinc, x, y, x1, y1, x2, y2;
int xsub, radx, rady;
int wdth, hgth, spcingx, spcingy;
struct dcoord b[4];
char ret;
char title[TITLEN];
char buf[TITLEN];
/*
* Set up the Title
*/
sprintf(title,"DEMO 2: Clipping capability");
palset(pal,0,255);
/*
* Set up the windows
*/
fillscreen(0);
setview(0,0,maxx,maxy);
drwstring(1,7,0,title,10,0);
sprintf(buf,"All pimitives automatically clip");
drwstring(1,7,0,buf,10,16);
wdth = (maxx + 1) * 4 / 9;
spcingx =